import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch((err) => err)
}

/* Layout */
import Layout from '@/layout'

export const baseRoutes = [
    {
        path: '/login',
        component: () => import('@/views/login/index'),
        hidden: true
    },
    {
        path: '/',
        component: Layout,
        redirect: 'dashboard',
        children: [
            {
                path: 'dashboard',
                name: 'Dashboard',
                component: () => import('@/views/dashboard/index'),
                meta: { title: '首页', icon: 'el-icon-house' }
            }
        ]
    },
    {
        path: '/bb',
        component: Layout,
        meta: { title: '测试展开', icon: 'el-icon-postcard' },
        children: [
            {
                path: 'news/list',
                name: 'NewsPage',
                component: () => import('@/views/news/index'),
                meta: { title: '资讯列表' }
            },
            {
                path: 'chat',
                name: 'NewsPage',
                component: () => import('@/views/chat'),
                meta: { title: '聊天' }
            },
            {
                path: 'echarts_01',
                name: 'NewsPage',
                component: () => import('@/views/echarts/echarts_01/index.vue'),
                meta: { title: '办税渠道监控平台' }
            },
            {
                path: 'echarts_04',
                name: 'NewsPage',
                component: () => import('@/views/echarts/echarts_04/index.vue'),
                meta: { title: 'ttt' }
            },
        ]
    },
    // {
    //     path: '/bb',
    //     component: Layout,
    //     meta: { title: '邦邦动态', icon: 'el-icon-postcard' },
    //     children: [
    //         {
    //             path: 'news/list',
    //             name: 'NewsPage',
    //             component: () => import('@/views/news/index'),
    //             meta: { title: '资讯列表' }
    //         },
    //         {
    //             path: 'news/edit/:id?',
    //             name: 'EditNewsPage',
    //             component: () => import('@/views/news/edit'),
    //             hidden: true,
    //             meta: { title: '编辑资讯', activeMenu: '/bb/news/list' }
    //         },
    //         {
    //             path: 'media/list',
    //             name: 'MediaPage',
    //             component: () => import('@/views/media/index'),
    //             meta: { title: '媒体列表' }
    //         },
    //         {
    //             path: 'media/edit/:id?',
    //             name: 'EditMediaPage',
    //             component: () => import('@/views/media/edit'),
    //             hidden: true,
    //             meta: { title: '编辑媒体', activeMenu: '/bb/media/list' }
    //         }
    //     ]
    // },
    {
        path: '*',
        redirect: '/404',
        hidden: true,
        component: () => import('@/views/404'),
        children: [{ path: '/404', meta: { title: '404' } }]
    }
    // 404 page must be placed at the end !!!
]

const createRouter = () =>
    new Router({
        base: 'admin',
        mode: 'history', // require service support
        scrollBehavior: () => ({ y: 0 }),
        routes: baseRoutes
    })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
